package com.fh.shop.api.mq.producer;

import com.alibaba.fastjson.JSON;
import com.fh.shop.api.mq.config.MQConstant;
import com.fh.shop.api.mq.message.MailMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MailProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMailMessage(MailMessage message) {
        String messageJson = JSON.toJSONString(message);
        rabbitTemplate.convertAndSend(MQConstant.Mail.EX, MQConstant.Mail.ROUTE_KEY, messageJson);
    }
}
